#ifndef _BUOLA_MEDIA_FFMPEG_COUTPUTCONTEXT_H_
#define _BUOLA_MEDIA_FFMPEG_COUTPUTCONTEXT_H_

#include "ffmpeg.h"

#include <blackbox/cstreamout.h>

namespace buola { namespace media { namespace ffmpeg {

class COutputVideoStream;
class COutputAudioStream;
    
class COutputContext
{
public:
    COutputContext(const std::string &pFormat);

    void Open(blackbox::CStreamOut<uint8_t> &pOut);
    
    COutputAudioStream *NewAudioStream(const std::string &pCodec);
    COutputVideoStream *NewVideoStream(const std::string &pCodec,const CSize_i &pSize);

    void WriteHeader();
    void WriteInterleaved(AVPacket *pPacket);
    void WriteTrailer();
    
private:
    static int WriteCB(void *pClosure,uint8_t *pBuf,int pSize);
    
private:
    AVFormatContext *mCtx;
    std::vector<COutputAudioStream*> mAudio;
    std::vector<COutputVideoStream*> mVideo;

    blackbox::CStreamOut<uint8_t> *mOutStream;
    off_t mOutOffset;
};

/*namespace ffmpeg*/ } /*namespace media*/ } /*namespace buola*/ }

#endif
